package com.yiidata.example.hadoop.mr;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;
import java.util.StringTokenizer;

/**
 *
 * <pre>
 *
 * Created by IntelliJ IDEA.
 * User: zhenqin
 * Date: 12-9-12
 * Time: 下午1:28
 * To change this template use File | Settings | File Templates.
 *
 *
 * </pre>
 *
 * @author ZhenQin
 *
 *
 */
public class WordCountMapper
        extends Mapper<LongWritable, Text, Text, IntWritable> {




    private final static IntWritable one = new IntWritable(1);

    private Text word = new Text();

    public WordCountMapper() {
        super();
    }


    @Override
    public void map(LongWritable key, Text value, 
    		Context context) throws IOException, InterruptedException {

        StringTokenizer tokenizer = new StringTokenizer(value.toString());
        while (tokenizer.hasMoreTokens()) {
            word.set(tokenizer.nextToken());
            context.write(word, one);
        }
    }
}
